<script setup lang="ts">
import { ref, reactive } from "vue";
import navbar from "@/components/navbar/navbar.vue";
import { onPageScroll } from "@dcloudio/uni-app";
import { toast } from "@/utils/tools";
const imgList = ref([]);
const navbarFixed = ref(false);

const data = reactive({
  formData: {
    detail: "",
    title: "",
  },
  rules: {},
});
const submit = () => {
  uni.showToast({
    title: "提交成功",
  });
};
const handleUploadImage = (files: any) => {
  // let files = e.file;
  files.forEach((item: any, index: number) => {
    // 这里可以进行上传操作
    imgList.value.push(item.path);
  });
};
const uploadImg = () => {
  uni.chooseImage({
    count: 9,
    sizeType: ["original", "compressed"],
    sourceType: ["album"],
    success: (imgRes: any) => {
      let files = imgRes.tempFiles;
      handleUploadImage(files);
    },
  });
};
const chooseLocation = () => {
  toast("选择位置");
};
const isImg = (url = "") => {
  if (
    url.indexOf(".png") > -1 ||
    url.indexOf(".jpg") > -1 ||
    url.indexOf(".jpeg") > -1 ||
    url.indexOf(".webp") > -1
  ) {
    return true;
  }
  return false;
};
const handleClose = (index: number = 0) => {
  imgList.value.splice(index, 1);
};
// 监听页面滚动
onPageScroll((e: any) => {
  // navbarFixed.value = e.scrollTop > 0 ? true : false
});
</script>
<template>
  <view class="container">
    <!-- <uv-form labelPosition="left" :model="data.formData" :rules="data.rules" ref="form"> -->
    <view class="row-box title-box">
      <input
        type="text"
        v-model="data.formData.title"
        placeholder="请输入奇石描述标题~"
      />
    </view>
    <view class="row-box info-box">
      <textarea
        maxlength="-1"
        v-model="data.formData.detail"
        placeholder="请详细描述奇石信息~"
      ></textarea>
    </view>
    <view class="form-upload-card form-input-bg">
      <view class="form-upload-item">
        <text> 奇石图片</text>
      </view>
      <!-- <uv-line color="#000000" ></uv-line> -->
      <!-- <view class="line"></view> -->
      <uv-line length="100%" color="#CECECE"></uv-line>

      <view class="form-upload">
        <view class="form-upload-img">
          <!-- <view v-for="(item, index) in imgList" :key="index" class="image">
            <image v-if="isImg(item)" :src="item" mode="scaleToFill" />
            <video v-else :src="item" />
            <view class="close flex flex-center" @click="handleClose(index)">
              <view class="close-line"></view>
            </view>
          </view> -->
          <image class="image" v-for="(item, index) in imgList" :src="item" mode="scaleToFill" />
          <view
            class="upload-btn-bg image"
            @click="uploadImg"
            v-if="imgList.length < 9"
          >
            <image
              class="icon-plus"
              src="@/static/images/plus.png"
              mode="scaleToFill"
            />
            <text class="upload-btn-text">添加图片</text>
          </view>
        </view>
        <!-- <uv-upload :fileList="imgList" name="1" multiple :maxCount="3" @afterRead="handleUploadImage"
                        uploadText="点击上传" @delete=""></uv-upload> -->
      </view>
    </view>
    <view class="form-card">
      <view class="form-card-title">
        <text>类型 / 品牌 / 成色</text>
      </view>
      <uv-line length="100%" color="#CECECE"></uv-line>
      <view class="form-card-title">
        <view class="form-card-radio">
          <view class="form-radio-title">
            <text>类型：</text>
          </view>
          <radio-group @change="" class="form-radio-group">
            <view class="form-radio-group">
              <label class="form-radio-item">
                <radio
                  :value="1"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>黄石</text>
                </view>
              </label>
              <label class="form-radio-item">
                <radio
                  :value="2"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>和田玉</text>
                </view>
              </label>
              <label class="form-radio-item">
                <radio
                  :value="3"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>其他</text>
                </view>
              </label>
            </view>
          </radio-group>

          <!-- <uv-radio-group>
                        <uv-radio label="黄石" name="1" />
                        <uv-radio label="和田玉" name="2" />
                        <uv-radio label="其他" name="3" />
                    </uv-radio-group> -->
        </view>
        <view class="line"></view>

        <view class="form-card-radio">
          <view class="form-radio-title">
            <text>品牌：</text>
          </view>
          <radio-group @change="" class="form-radio-group">
            <view class="form-radio-group">
              <label class="form-radio-item">
                <radio
                  :value="1"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>千艺坊</text>
                </view>
              </label>
              <label class="form-radio-item">
                <radio
                  :value="2"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>文韵奇石</text>
                </view>
              </label>
              <label class="form-radio-item">
                <radio
                  :value="3"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>其他</text>
                </view>
              </label>
            </view>
          </radio-group>
        </view>
        <view class="line"></view>

        <view class="form-card-radio">
          <view class="form-radio-title">
            <text>成色：</text>
          </view>
          <radio-group @change="" class="form-radio-group">
            <view class="form-radio-group">
              <label class="form-radio-item">
                <radio
                  :value="1"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>全新</text>
                </view>
              </label>
              <label class="form-radio-item">
                <radio
                  :value="2"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>无破损</text>
                </view>
              </label>
              <label class="form-radio-item">
                <radio
                  :value="3"
                  color="#BF0103"
                  style="transform: scale(0.9)"
                />
                <view class="form-radio-label">
                  <text>无其他影响</text>
                </view>
              </label>
            </view>
          </radio-group>
        </view>
      </view>
    </view>
    <view class="form-card form-item">
      <view class="form-item-label">
        <image
          src="@/static/images/orientation.png"
          mode="scaleToFill"
          class="form-item-icon"
        />
        <text>宝贝位置：</text>
      </view>
      <view class="form-input" @click="chooseLocation">
        <input placeholder="请选择" />
        <view class="form-input-suff">
          <image src="@/static/images/arrow.png" />
        </view>
      </view>
    </view>
    <view class="form-card form-item" style="margin-bottom: 0">
      <view class="form-item-label">
        <image
          src="@/static/images/money.png"
          mode="scaleToFill"
          class="form-item-icon"
        />
        <text>宝贝价格：</text>
      </view>
      <view class="form-input">
        <input type="text" class="form-input" placeholder="请输入宝贝价格" />
        <view class="form-input-suff">
          <text>单位：元</text>
        </view>
      </view>
    </view>
    <view class="line" style="margin: 0"></view>
    <view class="form-card form-item">
      <view class="form-item-label">
        <image
          src="@/static/images/money-origin.png"
          mode="scaleToFill"
          class="form-item-icon"
        />
        <text>宝贝原价：</text>
      </view>
      <view class="form-input">
        <input placeholder="请输入宝贝原价" class="form-input" />
        <view class="form-input-suff">
          <text>单位：元</text>
        </view>
      </view>
    </view>

    <view class="form-card form-item">
      <view class="form-item-label">
        <image
          src="@/static/images/delivery.png"
          mode="scaleToFill"
          class="form-item-icon"
        />
        <text>发货方式：</text>
      </view>
      <radio-group @change="" class="form-radio-group">
        <view class="form-radio-group">
          <label class="form-radio-item">
            <radio :value="1" color="#BF0103" style="transform: scale(0.9)" />
            <view class="form-radio-label">
              <text>包邮</text>
            </view>
          </label>
          <label class="form-radio-item">
            <radio :value="2" color="#BF0103" style="transform: scale(0.9)" />
            <view class="form-radio-label">
              <text>不包邮</text>
            </view>
          </label>
        </view>
      </radio-group>
    </view>

    <view class="btn-group">
      <button class="btn-cancel">取消</button>
      <button class="btn-publish">保存修改</button>
    </view>
  </view>
</template>
<style scoped lang="scss">
.container {
  position: relative;
  margin-top: 20rpx;
  padding: 0 30rpx;
  font-size: 28rpx;
  // box-sizing: border-box;

  .title-box {
    margin-bottom: 24rpx;
  }

  .info-box {
    height: 200rpx;
    margin-bottom: 24rpx;

    textarea {
      width: 100%;
      height: 100%;
      box-sizing: border-box;
    }
  }

  .form-input-item {
    margin-bottom: 30rpx;
    height: 100rpx;
    padding-left: 20rpx;
  }

  .form-textarea-item {
    position: static;
    height: 200rpx;
    // padding: 20rpx 0 0 20rpx;
    padding-top: 20rpx;
    // padding-left: 20rpx;
    margin-bottom: 30rpx;
  }

  .form-input-bg {
    background-color: #ffffff;
    border-radius: 24rpx;
    width: 100%;
  }

  .form-upload-card {
    height: 100%;
    margin-bottom: 30rpx;

    .form-upload-item {
      padding: 20rpx;
    }

    .form-upload {
      padding: 20rpx;
      display: flex;
      height: 100%;

      .form-upload-img {
        // width: 100%;
        flex-wrap: wrap;
        // width: 100%;
        height: 100%;
        display: flex;
        // grid-template-columns: 33% 33% 33%; // justify-content: space-evenly;
        // grid-template-rows: 58%; // justify-content: space-evenly;
        // align-items: center;
      }

      .image {
        // flex-grow: 1;
        // justify-content: space-around;
        width: 144rpx;
        height: 144rpx;
        margin-right: 30rpx;
        margin-bottom: 30rpx;

        image,
        video {
          width: 100%;
          height: 100%;
        }

        .icon-plus {
          width: 48rpx;
          height: 48rpx;
        }

        .close {
          position: absolute;
          right: -10rpx;
          top: -10rpx;
          background-color: #f3604e;
          width: 18px;
          height: 18px;
          border-radius: 50%;

          .close-line {
            background-color: #ffffff;
            height: 2px;
            width: 12px;
            border-radius: 1px;
          }
        }
      }

      .upload-btn-bg {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background-color: #efefef;
      }

      .upload-btn-text {
        color: #cecece;
        font-size: 24rpx;
      }
    }
  }

  .form-card {
    width: 100%;
    background-color: #ffffff;
    border-radius: 24rpx;
    margin-bottom: 20rpx;
    box-shadow: 2rpx 2rpx 4rpx 0rpx rgba(0, 0, 0, 0.1);

    .form-card-title {
      color: #333333;
      padding: 30rpx;
    }

    .form-card-radio {
      display: flex;
      padding: 8rpx 0;
    }
  }
}

.form-radio-title {
  width: 150rpx;
  font-size: 28rpx;
}

.form-radio-group {
  padding-right: 30rpx;
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.form-radio-item {
  display: flex;
  align-items: center;

  .form-radio-label {
    font-size: 25rpx;
  }
}

.form-input {
  border: none;
  font-size: 26rpx;
  position: relative;
  width: 100%;
  padding: 8rpx 0;

  .form-input-suff {
    position: absolute;
    right: 0;
    transform: translate(-50%, -50%);
    top: 50%;

    text {
      font-size: 24rpx;
      color: #bebebe;
    }

    image {
      width: 28rpx;
      height: 28rpx;
    }
  }
}

.btn-group {
  display: flex;
  justify-content: space-between;
  padding-bottom: 60rpx;

  .btn-cancel {
    background-color: transparent;
    border: 2rpx solid #999999;
    box-shadow: none;
    border-radius: 24rpx;
    width: 220rpx;
    height: 100rpx;
  }

  .btn-publish {
    // background-color: transparent;
    background-color: #df2b02;
    box-shadow: none;
    border: 2rpx solid #999999;
    border-radius: 24rpx;
    border: none;
    width: 420rpx;

    height: 100rpx;
  }
}

.line {
  margin: 0;
  border-bottom-width: 2rpx;
  border-bottom-style: solid;
  // width: 100%;
  transform: scaleY(0.5);
  border-color: #cecece;
  margin: 20rpx;
}

.form-item {
  display: flex;
  height: 100rpx;
  // justify-content: center;
  align-items: center;
}

.form-item-label {
  display: flex;
  flex-direction: row;
  width: 333rpx;

  text {
    font-size: 28rpx;
  }
}

.form-item-icon {
  margin-top: 7rpx;
  width: 32rpx;
  height: 32rpx;
  padding: 0 20rpx;
}
</style>
